$(function () {
  // 判断有没有中文
  function checkChineseFunc(val) {
    var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
    if (reg.test(val)) {
      // 包含中文
      return 1;
    } else {
      // 不包含中文
      return 0;
    }
  }
  //设备管理
  //基础配置
  //设备管理 打开窗口
  var orgId = localStorage.getItem('userOrgId');
  $('.configuration-trigger').on('click', function (event) {
    $('#configurationModal .deviceTypeSearchBtn').val('all');
    renderSmokeList();
    // 设备管理渲染组织树
    runderDevOrgList();

    event.preventDefault();
    $('.configuration-pop').addClass('is-visible3');

    // 设备管理 首次渲染
    configurationPage = 0;
    $("#configurationModal .devAddress").val('');
    $('.searchDevBox input').val('');
    $('#configurationModal .devTypeVal').val('全部')
    // $('#configurationModal .devTypeVal option').eq(0).attr('selected');

    configurationPageList(configurationPage, '', '', '', orgId);
    // 设备管理 获取总页数 点击分页渲染列表
    configurationSumPage(configurationPage, '', '', '', orgId);
    $('.pageJump input').val('');
    $('#configurationModal .devAddress').val('');
    $('#configurationModal .deviceTypeSearchBox .deviceTypeSearchBtn').val('all');

    $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li>');
    // 渲染导出功能的列表
    $.ajax({
      url: '/deviceStatus/data/list/bydevicetype?deviceTypeId=1',
      success: function (res) {
        $('#configurationTableExport tbody').html('');
        var data = res.data;
        for (var i = 0; i < data.length; i++) {
          var deviceName = data[i].device.deviceName ? data[i].device.deviceName : '';
          var usestatus = data[i].device.usestatus ? data[i].device.usestatus : '';
          var deviceTypeName = data[i].device.deviceType.deviceTypeName ? data[i].device.deviceType.deviceTypeName : '';
          var devCode = data[i].device.devCode ? data[i].device.devCode : '';
          var address = data[i].device.address ? data[i].device.address : '';
          var fixedPlace = data[i].device.fixedPlace ? data[i].device.fixedPlace : '';
          var latitude = data[i].device.latitude ? data[i].device.latitude : '';
          var longitude = data[i].device.longitude ? data[i].device.longitude : '';
          var installationDate = data[i].device.installationDate;
          var deadline = data[i].device.deadline;

          var linkMain1 = data[i].device.linkMain1 ? data[i].device.linkMain1 : '';
          var linkPhone1 = data[i].device.linkPhone1 ? data[i].device.linkPhone1 : '';
          var linkMain2 = data[i].device.linkMain2 ? data[i].device.linkMain2 : '';
          var linkPhone2 = data[i].device.linkPhone2 ? data[i].device.linkPhone2 : '';
          var linkMain3 = data[i].device.linkMain3 ? data[i].device.linkMain3 : '';
          var linkPhone3 = data[i].device.linkPhone3 ? data[i].device.linkPhone3 : '';
          var remark = data[i].device.remark ? data[i].device.remark : '';

          installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
          deadline = deadline ? moment(installationDate).format("YYYY-MM-DD") : '';
          $('#configurationTableExport tbody').append('<tr><td>' + deviceName + '</td><td>' + usestatus + '</td><td>' + deviceTypeName + '</td><td>' + devCode + '</td><td>' + address + '</td><td>' + fixedPlace + '</td><td>' + latitude + '</td><td>' + longitude + '</td><td>' + installationDate + '</td><td>' + deadline + '</td><td>' + linkMain1 + '</td><td>' + linkPhone1 + '</td><td>' + linkMain2 + '</td><td>' + linkPhone2 + '</td><td>' + linkMain3 + '</td><td>' + linkPhone3 + '</td><td>' + data[i].device.remark + '</td></tr>')
        }
        $('#configurationModal .exportBox .export').hide();
        $("#configurationTableExport caption").remove();
        $("#configurationTableExport").tableExport({
          formats: ["xlsx"]
        });
      }
    });
  });
  // 设备管理     刷新
  $('#configurationRefresh').on('click', function () {

    //        $('#configurationModal .devTypeVal').find("option:contains('全部')").attr("selected",true);
    $('#configurationModal .devTypeVal').val('全部')
    // 设备管理 首次渲染
    configurationPage = 0;
    $('.searchDevBox input').val('');
    $("#configurationModal .devAddress").val('');

    configurationPageList(configurationPage, '', '', '', orgId);
    // 设备管理 获取总页数 点击分页渲染列表
    configurationSumPage(configurationPage, '', '', '', orgId);
    $('.pageJump input').val('');
    $('#configurationModal .devAddress').val('');
    // 渲染导出功能的列表
    $.ajax({
      url: '/deviceStatus/data/list/bydevicetype?deviceTypeId=1',
      success: function (res) {
        $('#configurationTableExport tbody').html('');
        var data = res.data;
        for (var i = 0; i < data.length; i++) {
          var deviceName = data[i].device.deviceName ? data[i].device.deviceName : '';
          var usestatus = data[i].device.usestatus ? data[i].device.usestatus : '';
          var deviceTypeName = data[i].device.deviceType.deviceTypeName ? data[i].device.deviceType.deviceTypeName : '';
          var devCode = data[i].device.devCode ? data[i].device.devCode : '';
          var address = data[i].device.address ? data[i].device.address : '';
          var fixedPlace = data[i].device.fixedPlace ? data[i].device.fixedPlace : '';
          var latitude = data[i].device.latitude ? data[i].device.latitude : '';
          var longitude = data[i].device.longitude ? data[i].device.longitude : '';
          var installationDate = data[i].device.installationDate;
          var deadline = data[i].device.deadline;

          var linkMain1 = data[i].device.linkMain1 ? data[i].device.linkMain1 : '';
          var linkPhone1 = data[i].device.linkPhone1 ? data[i].device.linkPhone1 : '';
          var linkMain2 = data[i].device.linkMain2 ? data[i].device.linkMain2 : '';
          var linkPhone2 = data[i].device.linkPhone2 ? data[i].device.linkPhone2 : '';
          var linkMain3 = data[i].device.linkMain3 ? data[i].device.linkMain3 : '';
          var linkPhone3 = data[i].device.linkPhone3 ? data[i].device.linkPhone3 : '';
          var remark = data[i].device.remark ? data[i].device.remark : '';

          installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
          deadline = deadline ? moment(installationDate).format("YYYY-MM-DD") : '';
          $('#configurationTableExport tbody').append('<tr><td>' + deviceName + '</td><td>' + usestatus + '</td><td>' + deviceTypeName + '</td><td>' + devCode + '</td><td>' + address + '</td><td>' + fixedPlace + '</td><td>' + latitude + '</td><td>' + longitude + '</td><td>' + installationDate + '</td><td>' + deadline + '</td><td>' + linkMain1 + '</td><td>' + linkPhone1 + '</td><td>' + linkMain2 + '</td><td>' + linkPhone2 + '</td><td>' + linkMain3 + '</td><td>' + linkPhone3 + '</td><td>' + data[i].device.remark + '</td></tr>')
        }
        $('#configurationModal .exportBox .export').hide();
        $("#configurationTableExport caption").remove();
        $("#configurationTableExport").tableExport({
          formats: ["xlsx"]
        });
      }
    });
  });
  //设备管理  关闭窗口
  $('.configuration-pop').on('click', function (event) {
    if ($(event.target).is('.cd-popup-close') || $(event.target).is('.configuration-pop')) {
      event.preventDefault();
      $(this).removeClass('is-visible3');
    }
    if ($(event.target).is('.configuration-popup-close') || $(event.target).is('.configuration-pop')) {
      event.preventDefault();
      $(this).removeClass('is-visible3');
    }
    $('#configurationModal .devTypeVal').find("option:contains('全部')").attr("selected", true);

  });

  //设备管理 获取总页数 点击分页渲染列表
  function configurationSumPage(configurationPage, devCode, status, deviceTypeId, orgId) {
    var pageSum;
    var searchContent = $("#configurationModal .devAddress").val();
    if (searchContent) {
      searchContent = '&searchContent=' + searchContent;
    } else {
      searchContent = '';
    }
    var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
    if (deviceTypeId == 'all') {
      deviceTypeId = '';
    } else {
      deviceTypeId = '&deviceTypeId=' + deviceTypeId;
    }
    $.ajax({ ///deviceStatus/data/list/bydevicetype
      url: '/device/data/list/deviceManage?orgId=' + orgId + deviceTypeId + status + devCode + searchContent + '&size=11&page=' + configurationPage,
      //      async: false,
      success: function (result) {
        pageSum = result.data.totalPages;
        var totalElements = result.data.totalElements;
        $('#configurationModal .deviceTypeSearchBox .deviceSum span').text(totalElements);
        configurationPageFunc(pageSum, configurationPage, devCode, status, deviceTypeId, orgId);
      }
    });

  }
  //设备管理  分页功能
  function configurationPageFunc(pageSum, configurationPage, devCode, status, deviceTypeId) {
    if (pageSum <= 1) {
      $('#configurationPageBox .pageJump').hide();
    } else {
      $('#configurationPageBox .pageJump').show();
    }
    Page({
      num: pageSum, //页码数
      startnum: configurationPage, //指定页码
      elem: $('#configurationPage'), //指定的元素
      callback: function (n) { //回调函数
        console.log(n);
        $('#configurationPageBox .pageJump').show();
        $('#configurationSelectAll').prop('checked', false);
        configurationPageList(n - 1, devCode, status, deviceTypeId, orgId);
      }
    });
  };
  var configurationPage;
  //设备管理  页面渲染列表
  function configurationPageList(n, devCode, status, deviceTypeId, orgId) {
    var searchContent = $("#configurationModal .devAddress").val();
    if (searchContent) {
      searchContent = '&searchContent=' + searchContent;
    } else {
      searchContent = '';
    }
    var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
    if (deviceTypeId == 'all') {
      deviceTypeId = '';
    } else {
      deviceTypeId = '&deviceTypeId=' + deviceTypeId;
    }
    $.ajax({
      url: '/device/data/list/deviceManage?orgId=' + orgId + deviceTypeId + status + searchContent + devCode + '&page=' + n + '&size=' + 11,
      //      async: false,
      success: function (result) {
        console.log(result)
        $('#configurationModal .tbodyList').html('');
        configurationPage = n;
        var data = result.data.content;
        if (data.length != 0) {
          for (var i = 0; i < data.length; i++) {
            var beginTime = data[i].beginTime;
            beginTime = moment(beginTime).format("YYYY-MM-DD HH:mm:ss");
            var alarmId = data[i].alarmId;
            var status = data[i].status;
            // 烟感
            if (status == 1) {
              status = '火警';
            } else if (status == 3) {
              status = '故障';
            } else if (status == 4) {
              status = '低电';
            } else if (status == 7) {
              status = '正常';
            } else if (status == 10) {
              // 充电桩
              status = '正常';
            } else if (status == 12) {
              status = '拔出';
            } else if (status == 13) {
              status = '过载';
            } else if (status == 14) {
              status = '高温';
            } else if (status == 16) {
              status = '长时间充电';
            } else if (status == 17) {
              status = '故障';
            } else if (status == 20) {
              // 定位
              status = '正常';
            } else if (status == 30) {
              // 消火栓
              status = '正常';
            } else if (status == 31) {
              status = '低压';
            } else if (status == 32) {
              status = '高压';
            } else if (status == 33) {
              status = '故障';
            } else if (status == 40) {
              // 智慧用电
              status = '正常';
            } else if (status == 50) {
              // 水位检测
              status = '正常';
            } else if (status == 51) {
              status = '报警';
            } else if (status == 60) {
              // 视频
              status = '正常';
            }
            //                  <span class="configBtnStyle modifyBtn editDevice-trigger">修改</span>
            $('#configurationModal .tbodyList').append('<tr><td><input deviceytpeid="' + data[i].device.deviceType.deviceTypeId + '" type="checkbox" myid="' + data[i].device.organization.orgid + '" class="check" devid="' + data[i].device.id + '"></td><td>' + ((+n) * (+11) + (+i) + (+1)) + '</td><td>' + data[i].device.devCode + '</td><td>' + data[i].device.address + '</td><td>' + data[i].device.fireCount + '</td><td>' + status + '</td><td  devCode="' + data[i].device.devCode + '"longitude="' + data[i].device.longitude + '" latitude="' + data[i].device.latitude + '"><span class="configBtnStyle focusSelectBtn editDevice-trigger">查看详情</span><span class="configBtnStyle positionBtn closeModal configuration-popup-close" id="devicePositionBtn">定位</span></td></tr>')
            //$('#configurationModal .tbodyList').append('<tr><td><input type="checkbox" class="check" devid="' + data[i].id + '"></td><td>' + ((+n - 1) * (+8) + (+i) + (+1)) + '</td><td>' + data[i].devCode + '</td><td>' + data[i].address + '</td><td>' + data[i].fireCount + '</td><td>' + status + '</td><td  devCode="' + data[i].devCode + '"longitude="' + data[i].longitude + '" latitude="' + data[i].latitude + '"><span class="configBtnStyle focusSelectBtn editDevice-trigger">查看详情</span><span class="configBtnStyle positionBtn closeModal configuration-popup-close" id="devicePositionBtn">定位</span></td></tr>')
          }
        } else {
          if (configurationPage > 0) {
            configurationPage = configurationPage - 1;
          } else {
            return false;
          }
          var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
          var status = '';
          // status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';

          status = $('.searchDevStatusBox li.active').attr('myvalue');
          if (status == "all") {
            status = '';
          } else {
            status = '&status=' + status;
          }

          var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
          if (deviceTypeId == 'all') {
            deviceTypeId = '';
          } else {
            deviceTypeId = '&deviceTypeId=' + deviceTypeId;
          }
          // 设备管理 首次渲染
          configurationPageList(configurationPage, devCode, status, deviceTypeId, orgId);
          // 设备管理 获取总页数 点击分页渲染列表
          // configurationSumPage(configurationPage, devCode, status, deviceTypeId, orgId);
          $('.pageJump input').val('');
        }
      }
    });
  };
  //全选删除/全不选
  $('#configurationSelectAll').click(function () {
    var current = $(this).prop('checked');
    $('.check').prop({
      checked: current
    });
  });

  $('#configurationModal').on('click', '.check', function () {
    var flag = true;
    //  遍历下面所有的状态
    for (var i = 0; i < $('.check').length; i++) {
      //        如果其中一个不满足条件，把状态设置成false，立刻跳出循环
      if ($('.check').eq(i).prop('checked') == false) {
        flag = false;
        break;
      }
    }
    $('#configurationSelectAll').prop({
      checked: flag
    });
  });

  //设备管理 设备删除
  $("#configurationDelBtn").on('click', function () {
    if ($('#configurationModal .table .tbodyList input[type=checkbox]:checked')) {
      configurationPage += 1;
    }
    if ($('#configurationSelectAll').prop("checked")) {
      configurationPage = configurationPage - 1;
    }
    $('#configurationModal .table .tbodyList input[type=checkbox]:checked').each(function () {
      var devid = $(this).attr('devid');
      var myid = $(this).attr('myid');
      var devNum = +$('#devOrg' + myid + '>span>.text>s>.devNum').text() - 1;
      var devCode = $(this).parent().siblings().eq(1).text();
      var deviceTypeId = $(this).attr('deviceytpeid');
      $.ajax({
        url: '/device/del/' + devid,
        async: false,
        success: function (res) {
          console.log(res)
          $('#devOrg' + myid + '>span>.text>s>.devNum').text(devNum);
          // $('#devOrg' + myid).parents('ul').siblings().find('.text>s>.devNum').text(devNum);
          $('#devOrg' + myid).parents('ul').siblings().each(function () {
            var devNum1 = +$(this).find('.text>s>.devNum').text() - 1;
            $(this).find('.text>s>.devNum').text(devNum1);
          });
          // 百度地图删除对应点位
          // BaiDuMap.deletePoint(devCode);
          deleteDevPoint(deviceTypeId, devCode);

          tipModalFunc('删除成功!');
        }
      });
    });
    setTimeout(function () {
      var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
      var status = '';
      status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';

      if (status == "all") {
        status = '';
      } else {
        status = '&status=' + status;
      }
      var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
      if (deviceTypeId == 'all') {
        deviceTypeId = '';
      } else {
        deviceTypeId = '&deviceTypeId=' + deviceTypeId;
      }
      // 设备管理 删除后重新渲染
      configurationSumPage(configurationPage, devCode, status, deviceTypeId, orgId);
      configurationPageList(configurationPage, devCode, status, deviceTypeId, orgId);
      $('.pageJump input').val('');
      devSumFunc();
      devListSum();
      $('#configurationSelectAll').prop('checked', false)
    }, 0);

  });
  //设备管理 修改
  $('#configurationModal .manageModal .tableModal').on('click', '#deviceModifyBtn', function () {
    var $thisParent = $(this).parent();
    var devCode = $thisParent.attr('devcode');
    var alarmId = $thisParent.attr('alarmid');
    var disposeStatus = 1;
    var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
    if (deviceTypeId == 'all') {
      deviceTypeId = '';
    } else {
      deviceTypeId = '&deviceTypeId=' + deviceTypeId;
    }
    configurationHandle(devCode, alarmId, disposeStatus);

    // 设备管理 获取总页数 点击分页渲染列表
    configurationSumPage(configurationPage, devCode, status, deviceTypeId, orgId);
    // 设备管理 首次渲染
    configurationPageList(configurationPage, devCode, status, deviceTypeId, orgId);
    $('.pageJump input').val('');

    //    弹出修改页面模态框

  });

  //设备管理 点击定位定位到地图
  $('#configurationModal .tableModal .tbodyList').on('click', '#devicePositionBtn', function () {
    var $thisParent = $(this).parent();
    var longitude = $thisParent.attr('longitude');
    var latitude = $thisParent.attr('latitude');
    var devCode = $thisParent.attr('devCode');
    BaiDuMap.panTo(latitude, longitude);
    setTimeout(function () {
      BaiDuMap.popMenu(devCode);
    }, 700);
    //  BaiDuMap.deletePoint
    //  BaiDuMap.addMarker(fireCount, status, devCode, deviceName, address,latitude,longitude, linkMain1, linkPhone1, linkMain2, linkPhone2, linkMain3, linkPhone3, linkMain4, linkPhone4)

    if ($(event.target).is('.editDevice-popup-close') || $(event.target).is('.editDevice-pop')) {
      event.preventDefault();
      $(this).removeClass('is-visible3');
    }

  });
  // 模糊查询
  searchFunc();

  function searchFunc() {

    //模糊查询
    $('body').on('click', function () {
      $("#configurationModal .searchList").hide();
    });
    var fn = _.debounce(function () {
      $("#configurationModal .searchList").show();
      hide2border();
      if ($("#configurationModal .searchList li")) { //键盘抬起后就判断页面中是否存在这个元素,存在就删除
        $("#configurationModal .searchList li").remove();
      }
      var searchContent = $("#configurationModal .devAddress").val();
      searchContent = $.trim(searchContent);
      console.log(searchContent)

      var deviceTypeId = '';
      var status = $('.searchDevStatusBox li.active').attr('myvalue');
      if (status == 'all') {
        status = '';
      } else {
        status = '&status=' + status;
      }
      deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
      if (deviceTypeId == 'all') {
        deviceTypeId = '';
      } else {
        deviceTypeId = '&deviceTypeId=' + deviceTypeId;
      }
      //查询内容存在则搜索
      // 内容包含中文显示设备地址
      if (searchContent && checkChineseFunc(searchContent) == 1) {
        $.ajax({
          url: "/device/data/list/deviceManage?searchContent=" + searchContent + "&orgId=" + orgId + status + deviceTypeId,
          type: "GET",
          //                async: false,
          success: function (result) {
            console.log(result)
            var data = result.data.content;
            for (var i = 0; i < data.length; i++) {
              var searchAddress = data[i].device.address;
              var latitude = data[i].device.latitude;
              var longitude = data[i].device.longitude;
              var devCode = data[i].device.devCode;
              var checkChinese = checkChineseFunc(searchAddress);
              $("#configurationModal .searchList").append('<li devicecode="' + devCode + '" longitude="' + longitude + '" latitude="' + latitude + '">' + searchAddress + '</li>');
              hide2border();

            }
          }
        });
        // 内容不包含中文显示设备编号
      } else if (searchContent && checkChineseFunc(searchContent) == 0) {
        $.ajax({
          url: "/device/data/list/deviceManage?searchContent=" + searchContent + "&orgId=" + orgId + status + deviceTypeId,
          type: "GET",
          //                async: false,
          success: function (result) {
            console.log(result)
            var data = result.data.content;
            for (var i = 0; i < data.length; i++) {
              var searchAddress = data[i].address;
              var latitude = data[i].device.latitude;
              var longitude = data[i].device.longitude;
              var devCode = data[i].device.devCode;
              $("#configurationModal .searchList").append('<li devicecode="' + devCode + '" longitude="' + longitude + '" latitude="' + latitude + '">' + devCode + '</li>');
              hide2border();

            }
          }
        });
      }
      $("#configurationModal .searchList").show();
      hide2border();
    }, 500);
    $("#configurationModal .devAddress").on("input", function (e) {
      fn();
    });
    //直接输入地址,点击列表查询
    $("#configurationModal .searchList").on("click", "li", function () {
      $("#configurationModal .searchList").show();
      var liVal = $(this).text();
      liVal = $.trim(liVal);
      var searchVal = $("#configurationModal .devAddress").val(liVal);

      $("#configurationModal .searchList").html(""); //hide
      return false;
    });
  }

  function hide2border() {
    if (!($("#configurationModal .searchList>li").length)) {
      $("#configurationModal .searchList").hide();
    } else {
      $("#configurationModal .searchList").show();
    }
  }
  var clickSearchFn = _.debounce(function () {
    var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
    var status = $('.searchDevStatusBox li.active').attr('myvalue');
    if (status == 'all') {
      status = '';
    } else {
      status = '&status=' + status;
    }
    $('.pageJump input').val('');
    var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
    if (deviceTypeId == 'all') {
      deviceTypeId = '';
    } else {
      deviceTypeId = '&deviceTypeId=' + deviceTypeId;
    }

    configurationSumPage(configurationPage, devCode, status, deviceTypeId, orgId);
    configurationPageList(0, devCode, status, deviceTypeId, orgId);
    // renderSmokeList();
  }, 500);
  //点击设备管理搜索按钮 deviceManageSearchBtn
  $("#deviceManageSearchBtn").on('click', function () {
    clickSearchFn();
  });

  function devTypeStrFunc(devTypeStr) {
    if (devTypeStr == '001') {
      $('#editDeviceModal .addChargeItem').hide();
      $('#editDeviceModal .addFireplugItem').hide();
      $('#editDeviceModal .addChargeItem input').val('');
      $('#editDeviceModal .addFireplugItem input').val('');
      $('#editDeviceModal .addElectricityItem').hide();
      $('#editDeviceModal .addElectricityItem input').val('');
      $('#editDeviceModal .videoItem').hide();
      $('#editDeviceModal .videoItem input').val('');

      $('#editDeviceModal .deviceTypeIdVal').val('1');

      $('#editDeviceModal .hideChargeItem input').val('');
      $('#editDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');

    } else if (devTypeStr == '002') {
      $('#editDeviceModal .addChargeItem').show();
      $('#editDeviceModal .addFireplugItem').hide();
      $('#editDeviceModal .addFireplugItem input').val('');
      $('#editDeviceModal .addElectricityItem').hide();
      $('#editDeviceModal .addElectricityItem input').val('');
      $('#editDeviceModal .deviceTypeIdVal').val('2');
      $('#editDeviceModal .videoItem').hide();
      $('#editDeviceModal .videoItem input').val('');
      $('#editDeviceModal .hideChargeItem').hide();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');

    } else if (devTypeStr == '003') {
      $('#editDeviceModal .addChargeItem').hide();
      $('#editDeviceModal .addFireplugItem').hide();
      $('#editDeviceModal .addChargeItem input').val('');
      $('#editDeviceModal .addFireplugItem input').val('');
      $('#editDeviceModal .addElectricityItem').hide();
      $('#editDeviceModal .addElectricityItem input').val('');
      $('#editDeviceModal .deviceTypeIdVal').val('3');
      $('#editDeviceModal .videoItem').hide();
      $('#editDeviceModal .videoItem input').val('');
      $('#editDeviceModal .hideChargeItem input').val('');
      $('#editDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('绑定人1');
      $('.configuration .contactsText2').text('绑定人2');
      $('.configuration .contactsText3').text('绑定人3');

    } else if (devTypeStr == '004') {
      $('#editDeviceModal .addChargeItem').hide();
      $('#editDeviceModal .addFireplugItem').show();
      $('#editDeviceModal .addChargeItem input').val('');
      $('#editDeviceModal .addElectricityItem').hide();
      $('#editDeviceModal .addElectricityItem input').val('');
      $('#editDeviceModal .deviceTypeIdVal').val('4');
      $('#editDeviceModal .videoItem').hide();
      $('#editDeviceModal .videoItem input').val('');
      $('#editDeviceModal .hideChargeItem input').val('');
      $('#editDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == '005') {
      $('#editDeviceModal .addChargeItem').hide();
      $('#editDeviceModal .addFireplugItem').hide();
      $('#editDeviceModal .addChargeItem input').val('');
      $('#editDeviceModal .addFireplugItem input').val('');
      $('#editDeviceModal .addElectricityItem').show();
      $('#editDeviceModal .deviceTypeIdVal').val('5');
      $('#editDeviceModal .videoItem').hide();
      $('#editDeviceModal .videoItem input').val('');
      $('#editDeviceModal .hideChargeItem input').val('');
      $('#editDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == '006') {
      $('#editDeviceModal .addFireplugItem').hide();
      $('#editDeviceModal .addChargeItem').hide();
      $('#editDeviceModal .addChargeItem input').val('');
      $('#editDeviceModal .addFireplugItem input').val('');
      $('#editDeviceModal .addElectricityItem').hide();
      $('#editDeviceModal .addElectricityItem input').val('');

      $('#editDeviceModal .deviceTypeIdVal').val('6');
      $('#editDeviceModal .videoItem').hide();
      $('#editDeviceModal .videoItem input').val('');
      $('#editDeviceModal .hideChargeItem input').val('');
      $('#editDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == '007') {
      $('#editDeviceModal .addFireplugItem').hide();
      $('#editDeviceModal .addChargeItem').hide();
      $('#editDeviceModal .addChargeItem input').val('');
      $('#editDeviceModal .addFireplugItem input').val('');
      $('#editDeviceModal .addElectricityItem').hide();
      $('#editDeviceModal .addElectricityItem input').val('');

      $('#editDeviceModal .deviceTypeIdVal').val('7');
      $('#editDeviceModal .videoItem').show();
      $('#editDeviceModal .videoItem input').val('');
      $('#editDeviceModal .hideChargeItem input').val('');
      $('#editDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == '010') {

      $('#editDeviceModal .deviceTypeIdVal').val('010');
      addDeviceInputClear();
      $('#editDeviceModal .deviceTypeIdVal').val('010');
    } else if (devTypeStr == '011') {
      addDeviceInputClear();
      $('#editDeviceModal .deviceTypeIdVal').val('7');
    } else {
      $('#editDeviceModal .deviceTypeIdVal').find("option").removeAttr("selected");
      $('#editDeviceModal .deviceTypeIdVal option').eq(0).attr("selected", true);
    }
  }
  
  //设备编辑 打开窗口
  var editDeviceTriggerThis;
  $('body').on('click', ".editDevice-trigger", function (event) {
    editDeviceTriggerThis = $(this);
    $('.devEditSureBtn').hide();
    $('.devEditBtn').show();
    event.preventDefault();
    $('.editDevice-pop').addClass('is-visible3');

    // var devTypeStr = $('#configurationModal .deviceTypeSearchBtn').val();

    //获取当前设备信息
    var devCode = $(this).parent().attr('devCode');

    $('#editDeviceForm input.form-control').attr('disabled', 'disabled');
    $('#editDeviceForm select.form-control').attr('disabled', 'disabled');
    $('#editDeviceForm select.form-control').addClass('disabledStyle');
    $('#editDeviceForm input.form-control').addClass('disabledStyle');
    $.ajax({
      url: '/organization/list',
      async: false,
      success: function (res) {
        console.log(res)
        $('#editDeviceModal .orgidval').html('');
        for (var i = 0; i < res.data.length; i++) {
          $('#editDeviceModal .orgidval').append('<option value="' + res.data[i].id + '">' + res.data[i].orgName + '</option>')
        }
      }
    });
    $.ajax({
      url: '/deviceStatus/get/code?deviceCode=' + devCode,
      async: false,
      success: function (res) {
        console.log(res)
        var deviceid = res.data[0][0].id;
        var deviceName = res.data[0][0].deviceName;
        var usestatus = res.data[0][0].usestatus;
        var deviceTypeName = res.data[0][0].deviceType.deviceTypeName;
        var deviceTypeId = res.data[0][0].deviceType.deviceTypeId;
        var devCode = res.data[0][0].devCode;
        var address = res.data[0][0].address;
        var fixedPlace = res.data[0][0].fixedPlace;
        var latitude = res.data[0][0].latitude;
        var longitude = res.data[0][0].longitude;
        var installationDate = res.data[0][0].installationDate;
        var deadline = res.data[0][0].deadline;
        var linkMain1 = res.data[0][0].linkMain1;
        var linkMain2 = res.data[0][0].linkMain2;
        var linkMain3 = res.data[0][0].linkMain3;
        var linkPhone1 = res.data[0][0].linkPhone1;
        var linkPhone2 = res.data[0][0].linkPhone2;
        var linkPhone3 = res.data[0][0].linkPhone3;
        var remark = res.data[0][0].remark;
        var fireCount = res.data[0][0].fireCount;

        var chargingInterfaceNumber = res.data[0][0].chargingInterfaceNumber;
        var manufacturer = res.data[0][0].manufacturer;
        var waterGage = res.data[0][0].waterGage;
        var waterLevel = res.data[0][0].waterLevel;
        var urrentMarginThreshold = res.data[0][0].urrentMarginThreshold;
        var temperatureThreshold = res.data[0][0].temperatureThreshold;
        var cameraUrl = res.data[0][0].cameraUrl;
        var streamServer = res.data[0][0].streamServer;

        installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
        deadline = deadline ? moment(deadline).format("YYYY-MM-DD") : '';
        devTypeStrFunc(deviceTypeId);
        $('#editDeviceForm input[name="id"]').val(deviceid);
        $('#editDeviceForm input[name="deviceName"]').val(deviceName);
        $("#editDeviceForm select[name='usestatus']").val(usestatus);
        // $('#editDeviceForm input[name="deviceTypeId"]').val(deviceTypeName);
        $('#editDeviceForm input[name="devCode"]').val(devCode);
        $('#editDeviceForm input[name="address"]').val(address);
        $('#editDeviceForm input[name="fixedPlace"]').val(fixedPlace);
        $('#editDeviceForm input[name="latitude"]').val(latitude);
        $('#editDeviceForm input[name="longitude"]').val(longitude);
        $('#editDeviceForm input[name="installationDate"]').val(installationDate);
        $('#editDeviceForm input[name="deadline"]').val(deadline);
        $('#editDeviceForm input[name="linkMain1"]').val(linkMain1);
        $('#editDeviceForm input[name="linkMain2"]').val(linkMain2);
        $('#editDeviceForm input[name="linkMain3"]').val(linkMain3);
        $('#editDeviceForm input[name="linkPhone1"]').val(linkPhone1);
        $('#editDeviceForm input[name="linkPhone2"]').val(linkPhone2);
        $('#editDeviceForm input[name="linkPhone3"]').val(linkPhone3);
        $('#editDeviceForm input[name="remark"]').val(remark);
        $('#editDeviceForm input[name="fireCount"]').val(fireCount);

        $('#editDeviceForm input[name="chargingInterfaceNumber"]').val(chargingInterfaceNumber);
        $('#editDeviceForm input[name="manufacturer"]').val(manufacturer);
        $('#editDeviceForm input[name="waterGage"]').val(waterGage);
        $('#editDeviceForm input[name="waterLevel"]').val(waterLevel);
        $('#editDeviceForm input[name="urrentMarginThreshold"]').val(urrentMarginThreshold);
        $('#editDeviceForm input[name="temperatureThreshold"]').val(temperatureThreshold);
        $('#editDeviceForm input[name="cameraUrl"]').val(cameraUrl);
        $('#editDeviceForm input[name="streamServer"]').val(streamServer);
        var orgname = res.data[0][1];
        $('#editDeviceForm .orgidval').find("option:contains('" + orgname + "')").attr("selected", true);
        // $('#editDeviceForm .deviceTypeIdVal option').removeAttr('selected')
        // $('#editDeviceForm .deviceTypeIdVal').find("option:contains('" + deviceTypeName + "')").attr("selected", true);
        $('#editDeviceForm .deviceTypeIdVal').val(deviceTypeId);
      }
    });
    //	$('#editDeviceForm input.form-control').attr('disabled');
  });
  //设备编辑  关闭窗口
  $('.editDevice-pop').on('click', function (event) {
    if ($(event.target).is('.cd-popup-close') || $(event.target).is('.editDevice-pop')) {
      event.preventDefault();
      $(this).removeClass('is-visible3');
      //Modal验证销毁重构
      $("#editDeviceForm").data('bootstrapValidator').destroy();
      $('#editDeviceForm').data('bootstrapValidator', null);
      editDeviceFormValidator();
      $('#editDeviceForm input').val('');
    }
  });
  // 编辑
  editDeviceFormValidator();

  function editDeviceFormValidator() {
    $("#editDeviceForm").bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        devCode: {
          message: '设备编号验证失败',
          validators: {
            notEmpty: {
              message: '设备编号不能为空'
            }
          }
        },
        deviceTypeId: {
          validators: {
            notEmpty: {
              message: '设备类型不能为空'
            }
          }
        },
        deviceName: {
          validators: {
            notEmpty: {
              message: '设备名称不能为空'
            }
          }
        },
        address: {
          validators: {
            notEmpty: {
              message: '安装地址不能为空'
            }
          }
        },
        fixedPlace: {
          validators: {
            notEmpty: {
              message: '安装场所不能为空'
            }
          }
        },
        //            installationDate: {
        //                validators: {
        //                    notEmpty: {
        //                        message: '安装日期不能为空'
        //                    }
        //                }
        //            },
        latitude: {
          validators: {
            notEmpty: {
              message: '经度不能为空'
            }
          }
        },
        longitude: {
          validators: {
            notEmpty: {
              message: '纬度不能为空'
            }
          }
        }
      }
    }).on("success.form.bv", function (e) {
      e.preventDefault();
      var $form = $(e.target);
      var nextUrl;
      nextUrl = "/device/save?" + $form.serialize();
      console.log($form.serialize())
      $.ajax({
        url: nextUrl,
        type: 'POST',
        //            data: $form.serialize(),
        success: function (result) {
          if (result.status == 200) {
            $('.editDevice-pop').removeClass('is-visible3');
            var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
            var status = '';
            status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';
            var deviceCode = $("#editDeviceForm .devCodeVal").val();
            var latitude = $("#configurationModal .latitudeVal").val();
            var longitude = $("#configurationModal .longitudeVal").val();
            editDeviceTriggerThis.parent().attr('devcode', deviceCode);
            editDeviceTriggerThis.parent().attr('longitude', longitude);
            editDeviceTriggerThis.parent().attr('latitude', latitude);
            if (status == "all") {
              status = '';
            } else {
              status = '&status=' + status;
            }
            var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
            if (deviceTypeId == 'all') {
              deviceTypeId = '';
            } else {
              deviceTypeId = '&deviceTypeId=' + deviceTypeId;
            }
            // 设备管理 修改后重新渲染
            configurationPageList(configurationPage, devCode, status, deviceTypeId, orgId);
            tipModalFunc('修改成功!');

            $("#editDeviceForm").data('bootstrapValidator').destroy();
            $('#editDeviceForm').data('bootstrapValidator', null);
            editDeviceFormValidator();
            $('#editDeviceForm input').val('');
          } else {
            console.log(result.message);
          }
        }

      });
    });
  }
  //点击修改按钮允许修改
  $("#deviceAllowEdit").on('click', function () {
    $('.devEditSureBtn').show();
    $('.devEditBtn').hide();
    $('#editDeviceForm input.form-control').removeAttr('disabled');
    $('#editDeviceForm select.form-control').removeAttr('disabled');
    $('#editDeviceForm select.form-control').removeClass('disabledStyle');
    $('#editDeviceForm input.form-control').removeClass('disabledStyle');
  });
  // -------------------------------添加------------------------
  //设备添加 打开窗口
  $('body').on('click', '.addDevice-trigger', function (event) {
    var devTypeStr = $('#configurationModal .deviceTypeSearchBtn').val();
    event.preventDefault();
    $('#addDeviceForm select option').eq(0).prop('selected');
    $('.addDevice-pop').addClass('is-visible3');
    $.ajax({
      url: '/organization/list',
      //		 async:false,
      success: function (res) {
        console.log(res)
        $('#addAccountModal .choiceOrgList').html('');
        $('#addDeviceModal .addAccountOrgList').html('');
        for (var i = 0; i < res.data.length; i++) {
          $('#addDeviceModal .addAccountOrgList').append('<option orgid="' + res.data[i].orgid + '" value="' + res.data[i].id + '">' + res.data[i].orgName + '</option>')
        }
      }
    });
    $('#addDeviceModal .addAccountOrgList option').eq(0).attr("selected", true);
    // $('#addDeviceModal .deviceTypeIdVal option').eq(0).attr("selected", true);
    $('#addDeviceModal .usestatusVal option').eq(0).attr("selected", true);
    // 判断设备类型
    console.log(devTypeStr);
    if (devTypeStr == 1) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();

      // 设置此项选中
      // $('#addDeviceModal .deviceTypeIdVal').find("option").removeAttr("selected");
      // $('#addDeviceModal .deviceTypeIdVal').find("option:contains('烟感')").attr("selected",true);
      $('#addDeviceModal .deviceTypeIdVal').val('1');
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == 2) {
      $('#addDeviceModal .addChargeItem').show();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .deviceTypeIdVal').val('2');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').hide();
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == 3) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .deviceTypeIdVal').val('3');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
      $('.configuration .contactsText1').text('绑定人1');
      $('.configuration .contactsText2').text('绑定人2');
      $('.configuration .contactsText3').text('绑定人3');

    } else if (devTypeStr == 4) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').show();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .deviceTypeIdVal').val('4');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == 5) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').show();
      $('#addDeviceModal .deviceTypeIdVal').val('5');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == 6) {
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');

      $('#addDeviceModal .deviceTypeIdVal').val('6');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (devTypeStr == 7) {
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');

      $('#addDeviceModal .deviceTypeIdVal').val('7');
      $('#addDeviceModal .videoItem').show();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();

      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    }else if (devTypeStr == 10) {
      addDeviceInputClear();
      $('#addDeviceModal .deviceTypeIdVal').val('10');
    }else if (devTypeStr == 11) {
      addDeviceInputClear();
      $('#addDeviceModal .deviceTypeIdVal').val('11');
    } else {
      $('#addDeviceModal .deviceTypeIdVal').find("option").removeAttr("selected");
      $('#addDeviceModal .deviceTypeIdVal option').eq(0).attr("selected", true);
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');

      $('#addDeviceModal .deviceTypeIdVal').val('1');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
    }

  });

  // 点击添加页面中的设备选项时，根据设备类型选择显示或隐藏的各项
  $('#addDeviceModal .deviceTypeIdVal').change(function () {
    var val = $(this).val();
    if (val == 1) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
      $('#addDeviceModal .hideChargeItem input').val('');
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (val == 2) {
      $('#addDeviceModal .addChargeItem').show();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').hide();
      $('#addDeviceModal .hideChargeItem input').val('');
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (val == 3) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
      $('#addDeviceModal .hideChargeItem input').val('');
      $('.configuration .contactsText1').text('绑定人1');
      $('.configuration .contactsText2').text('绑定人2');
      $('.configuration .contactsText3').text('绑定人3');

    } else if (val == 4) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').show();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
      $('#addDeviceModal .hideChargeItem input').val('');
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');

    } else if (val == 5) {
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').show();
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
      $('#addDeviceModal .hideChargeItem input').val('');
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');

    } else if (val == 6) {
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .videoItem').hide();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
      $('#addDeviceModal .hideChargeItem input').val('');
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');
    } else if (val == 7) {
      $('#addDeviceModal .addFireplugItem').hide();
      $('#addDeviceModal .addChargeItem').hide();
      $('#addDeviceModal .addChargeItem input').val('');
      $('#addDeviceModal .addFireplugItem input').val('');
      $('#addDeviceModal .addElectricityItem').hide();
      $('#addDeviceModal .addElectricityItem input').val('');
      $('#addDeviceModal .videoItem').show();
      $('#addDeviceModal .videoItem input').val('');
      $('#addDeviceModal .hideChargeItem').show();
      $('#addDeviceModal .hideChargeItem input').val('');
      $('.configuration .contactsText1').text('联系人1');
      $('.configuration .contactsText2').text('联系人2');
      $('.configuration .contactsText3').text('联系人3');

    } else if (val == 10) {
      addDeviceInputClear();
    } else if (val == 11) {
      addDeviceInputClear();
    }
  });
  function addDeviceInputClear(){
    $('#addDeviceModal .addFireplugItem').hide();
    $('#addDeviceModal .addChargeItem').hide();
    $('#addDeviceModal .addChargeItem input').val('');
    $('#addDeviceModal .addFireplugItem input').val('');
    $('#addDeviceModal .addElectricityItem').hide();
    $('#addDeviceModal .addElectricityItem input').val('');
    $('#addDeviceModal .videoItem').hide();
    $('#addDeviceModal .videoItem input').val('');
    $('#addDeviceModal .hideChargeItem').hide();
    $('#addDeviceModal .hideChargeItem input').val('');
    $('.configuration .contactsText1').text('联系人1');
    $('.configuration .contactsText2').text('联系人2');
    $('.configuration .contactsText3').text('联系人3');
  }
  //设备添加  关闭窗口
  $('.addDevice-pop').on('click', function (event) {
    if ($(event.target).is('.cd-popup-close') || $(event.target).is('.addDevice-pop')) {
      event.preventDefault();
      $(this).removeClass('is-visible3');
      //Modal验证销毁重构
      $("#addDeviceForm").data('bootstrapValidator').destroy();
      $('#addDeviceForm').data('bootstrapValidator', null);
      deviceFormValidator();
      $('#addDeviceForm input').val('');
    }
  });
  //设备添加
  deviceFormValidator();

  function deviceFormValidator() {
    $("#addDeviceForm").bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        devCode: {
          message: '设备编号验证失败',
          validators: {
            notEmpty: {
              message: '设备编号不能为空'
            },
            remote: {
              url: '/device/validateName',
              data: {
                'devCode': $('#addDeviceForm .devCodeVal').val(),
              },
              type: 'POST',
              delay: 1000,
              message: "设备编号已存在",
            },
          }
        },
        deviceTypeId: {
          validators: {
            notEmpty: {
              message: '设备类型不能为空'
            }
          }
        },
        deviceName: {
          validators: {
            notEmpty: {
              message: '设备名称不能为空'
            }
          }
        },
        address: {
          validators: {
            notEmpty: {
              message: '安装地址不能为空'
            }
          }
        },
        fixedPlace: {
          validators: {
            notEmpty: {
              message: '安装场所不能为空'
            }
          }
        },
        //            installationDate: {
        //                validators: {
        //                    notEmpty: {
        //                        message: '安装日期不能为空'
        //                    }
        //                }
        //            },
        latitude: {
          validators: {
            notEmpty: {
              message: '经度不能为空'
            }
          }
        },
        longitude: {
          validators: {
            notEmpty: {
              message: '纬度不能为空'
            }
          }
        }
      }
    }).on("success.form.bv", function (e) {
      e.preventDefault();
      var $form = $(e.target);
      var nextUrl;
      nextUrl = "/device/save",
        console.log($form.serialize())
      $.ajax({
        url: nextUrl,
        type: 'POST',
        data: $form.serialize(),
        success: function (result) {
          console.log(result)
          if (result.status == 200) {
            // 添加成功后渲染组织树设备数量
            var myid = $('#addDeviceForm .addAccountOrgList option:selected').attr('orgid');
            var devNum = +$('#devOrg' + myid + '>span>.text>s>.devNum').text() + 1;
            $('#devOrg' + myid + '>span>.text>s>.devNum').text(devNum);
            $('#devOrg' + myid).parents('ul').siblings().each(function () {
              var devNum1 = +$(this).find('.text>s>.devNum').text() + 1;
              $(this).find('.text>s>.devNum').text(devNum1);
            });
            // $('#devOrg' + myid).parents('ul').siblings().find('.text>s>.devNum').text(devNum);

            $('.addDevice-pop').removeClass('is-visible3');
            //Modal验证销毁重构
            $("#addDeviceForm").data('bootstrapValidator').destroy();
            $('#addDeviceForm').data('bootstrapValidator', null);
            $('#addDeviceForm input').val('');
            deviceFormValidator();
            devSumFunc();
            devListSum();
            tipModalFunc('添加成功!');

            var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
            var status = '';
            status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';

            if (status == "all") {
              status = '';
            } else {
              status = '&status=' + status;
            }
            var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
            if (deviceTypeId == 'all') {
              deviceTypeId = '';
            } else {
              deviceTypeId = '&deviceTypeId=' + deviceTypeId;
            }
            // 设备管理 获取总页数 点击分页渲染列表
            configurationSumPage(configurationPage + 1, devCode, status, deviceTypeId, orgId);
            // 设备管理 渲染列表
            configurationPageList(configurationPage, devCode, status, deviceTypeId, orgId);

            // 添加设备成功后，渲染地图
            // TODO

          } else {
            console.log(result.message);
          }
        }

      });
    });
  }
  //-----------------------------------------------------------------------------
  // renderSmokeList();
  function renderSmokeList() {
    //  /device/data/list/deviceManage?orgId=1&deviceTypeId=1&searchContent=c4cd8232e6e2ef44&status=3
    $('.configuration-pop').addClass('is-visible3');

    // 设备管理 首次渲染
    configurationPage = 0;
    $("#configurationModal .devAddress").val('');
    $('.searchDevBox input').val('');
    $('#configurationModal .devTypeVal').val('全部')
    //        $('#configurationModal .devTypeVal option').eq(0).attr('selected');
    var deviceTypeId = '';

    var status = $('.searchDevStatusBox li.active').attr('myvalue');
    if (status == 'all') {
      status = '';
    } else {
      status = '&status=' + status;
    }
    deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
    if (deviceTypeId == 'all') {
      deviceTypeId = '';
    } else {
      deviceTypeId = '&deviceTypeId=' + deviceTypeId;
    }
    configurationPageList(configurationPage, '', status, deviceTypeId, orgId);
    // 设备管理 获取总页数 点击分页渲染列表
    configurationSumPage(configurationPage, '', status, deviceTypeId, orgId);
    $('.pageJump input').val('');
    $('#configurationModal .devAddress').val('');

    // 渲染导出功能的列表
    // $.ajax({
    //     url: '/deviceStatus/data/list/bydevicetype?deviceTypeId=1',
    //     success: function (res) {
    //         $('#configurationTableExport tbody').html('');
    //         var data = res.data;
    //         for (var i = 0; i < data.length; i++) {
    //             var deviceName = data[i].device.deviceName ? data[i].device.deviceName : '';
    //             var usestatus = data[i].device.usestatus ? data[i].device.usestatus : '';
    //             var deviceTypeName = data[i].device.deviceType.deviceTypeName ? data[i].device.deviceType.deviceTypeName : '';
    //             var devCode = data[i].device.devCode ? data[i].device.devCode : '';
    //             var address = data[i].device.address ? data[i].device.address : '';
    //             var fixedPlace = data[i].device.fixedPlace ? data[i].device.fixedPlace : '';
    //             var latitude = data[i].device.latitude ? data[i].device.latitude : '';
    //             var longitude = data[i].device.longitude ? data[i].device.longitude : '';
    //             var installationDate = data[i].device.installationDate;
    //             var deadline = data[i].device.deadline;

    //             var linkMain1 = data[i].device.linkMain1 ? data[i].device.linkMain1 : '';
    //             var linkPhone1 = data[i].device.linkPhone1 ? data[i].device.linkPhone1 : '';
    //             var linkMain2 = data[i].device.linkMain2 ? data[i].device.linkMain2 : '';
    //             var linkPhone2 = data[i].device.linkPhone2 ? data[i].device.linkPhone2 : '';
    //             var linkMain3 = data[i].device.linkMain3 ? data[i].device.linkMain3 : '';
    //             var linkPhone3 = data[i].device.linkPhone3 ? data[i].device.linkPhone3 : '';
    //             var remark = data[i].device.remark ? data[i].device.remark : '';

    //             installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
    //             deadline = deadline ? moment(installationDate).format("YYYY-MM-DD") : '';
    //             $('#configurationTableExport tbody').append('<tr><td>' + deviceName + '</td><td>' + usestatus + '</td><td>' + deviceTypeName + '</td><td>' + devCode + '</td><td>' + address + '</td><td>' + fixedPlace + '</td><td>' + latitude + '</td><td>' + longitude + '</td><td>' + installationDate + '</td><td>' + deadline + '</td><td>' + linkMain1 + '</td><td>' + linkPhone1 + '</td><td>' + linkMain2 + '</td><td>' + linkPhone2 + '</td><td>' + linkMain3 + '</td><td>' + linkPhone3 + '</td><td>' + data[i].device.remark + '</td></tr>')
    //         }
    //         $('#configurationModal .exportBox .export').hide();
    //         $("#configurationTableExport caption").remove();
    //         $("#configurationTableExport").tableExport({
    //             formats: ["xlsx"]
    //         });
    //     }
    // });
  }

  // 设备管理中的设备筛选
  $("#configurationModal .selectDevBtn-title span").click(function () {

    $(this).parent().siblings().stop().slideDown("slow");
    $(this).stop().addClass('active');
    $(this).parent().parent().siblings().find('#configurationModal .selectDevBtn-content').stop().slideUp("slow");
    $(this).parent().parent().siblings().find('#configurationModal .selectDevBtn-title span').stop().removeClass("active");
    return false;
  });
  $('#configurationModal .selectDevBtn-content ul li').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    //return false;
  });
  $('body').click(function () {
    $('#configurationModal .selectDevBtn-content').stop().slideUp("slow");
    $('#configurationModal .selectDevBtn-title span').removeClass('active');
    $('#configurationModal .selectDevBtn-content ul li').removeClass('active')
  });

  // 第二版

  $('#configurationModal .deviceTypeSearchBtn').change(function () {
    var val = $(this).val();
    console.log(val)
    if (val == 1) {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li><li myvalue="7">正常</li><li myvalue="4">低电</li><li myvalue="1">报警</li><li myvalue="3">故障</li>');
    } else if (val == 2) {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li><li myvalue="10">正常</li><li myvalue="12">拔出</li><li myvalue="13">过载</li><li myvalue="14">高温</li><li myvalue="16">长时间充电</li><li myvalue="17">故障</li>');
    } else if (val == 3) {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li>');
    } else if (val == 4) {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li><li myvalue="30">正常</li><li myvalue="31">低压</li><li myvalue="32">高压</li><li myvalue="33">故障</li>');
    } else if (val == 5) {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li>');
      //$('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li><li myvalue="10">正常</li><li myvalue="12">拔出</li><li myvalue="13">过载</li><li myvalue="14">高温</li><li myvalue="16">长时间充电</li><li myvalue="17">故障</li>');
    } else if (val == 6) {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li><li myvalue="50">正常</li><li myvalue="51">报警</li>');
    } else if (val == 7) {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li><li myvalue="60">正常</li>');
    } else {
      $('#configurationModal .searchDevStatusBox').html('<li class="active" myvalue="all">全部</li>');
    }
    renderSmokeList();
  });
  $('.searchDevStatusBox').on('click', 'li', function () {
    $(this).addClass('active').siblings().removeClass('active');
    renderSmokeList();
  });

  $(".devOrgList_scroll").yi_scroll();
  // 设备管理渲染组织树
  // runderDevOrgList();

  function runderDevOrgList() {
    $.ajax({
      type: 'get',
      // url: '/organization/list',
      url: '/organization/data/list/count',
      dataType: 'html',
      async: false,
      success: function (data) {
        var data = JSON.parse(data);
        var data = data.data;
        console.log(data)
        $(".devOrgList>div>div>ul").html('');
        path = data[0].path;
        parentid = data[0].id;
        for (var i = 0; i < data.length; i++) {
          var dataId = data[i].organization.orgid;
          // 如果最顶层组织没有parent
          if (!data[0].parent) {
            if (i == 0) {
              $(".devOrgList>div>div>ul").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg"></ul></li>'); //<li class="orgml20"><span><i class="stretchImg stretchImgStyle"></i><i class="text">11</i></span><ul class="none"></ul></li>

            } else if (data[i].organization.parent && !data[i].organization.parent.parent) {
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg1"></ul></li>')

            } else if (data[i].organization.parent.parent && !data[i].organization.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg1").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg2"></ul></li>')
            } else if (data[i].organization.parent.parent.parent && !data[i].organization.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg2").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg3"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg3").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg4"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg4").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg5"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg5").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg6"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg6").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg7"></ul></li>')
            }
          } else if (data[0].parent && !data[0].parent.parent) {
            //                      如果最顶层组织有一个parent
            if (i == 0) {
              $(".devOrgList>div>div>ul").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg1"></ul></li>'); //<li class="orgml20"><span><i class="stretchImg stretchImgStyle"></i><i class="text">11</i></span><ul class="none"></ul></li>
            } else if (data[i].organization.parent.parent && !data[i].organization.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg1").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg2"></ul></li>')
            } else if (data[i].organization.parent.parent.parent && !data[i].organization.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg2").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg3"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg3").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg4"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg4").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg5"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg5").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg6"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg6").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg7"></ul></li>')
            }
          } else if (data[0].parent.parent && !data[0].parent.parent.parent) {
            //                      如果最顶层组织有两个parent

            if (i == 0) {
              $(".devOrgList>div>div>ul").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg2"></ul></li>'); //<li class="orgml20"><span><i class="stretchImg stretchImgStyle"></i><i class="text">11</i></span><ul class="none"></ul></li>
            } else if (data[i].organization.parent.parent.parent && !data[i].organization.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg2").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg3"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg3").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg4"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg4").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg5"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg5").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg6"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg6").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg7"></ul></li>')
            }
          } else if (data[0].parent.parent.parent && !data[0].parent.parent.parent.parent) {
            console.log(!!data[0].parent.parent.parent)
            //                      如果最顶层组织有三个parent

            if (i == 0) {
              $(".devOrgList>div>div>ul").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg3"></ul></li>'); //<li class="orgml20"><span><i class="stretchImg stretchImgStyle"></i><i class="text">11</i></span><ul class="none"></ul></li>
            } else if (data[i].organization.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg3").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg4"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg4").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg5"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg5").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg6"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg6").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg7"></ul></li>')
            }
          } else if (data[0].parent.parent.parent.parent && !data[0].parent.parent.parent.parent.parent) {
            //                      如果最顶层组织有四个parent

            if (i == 0) {
              $(".devOrgList>div>div>ul").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg4"></ul></li>'); //<li class="orgml20"><span><i class="stretchImg stretchImgStyle"></i><i class="text">11</i></span><ul class="none"></ul></li>
            } else if (data[i].organization.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg4").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg5"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg5").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg6"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg6").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg7"></ul></li>')
            }
          } else if (data[0].parent.parent.parent.parent.parent && !data[0].parent.parent.parent.parent.parent.parent) {
            //                      如果最顶层组织有五个parent

            if (i == 0) {
              $(".devOrgList>div>div>ul").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg5"></ul></li>'); //<li class="orgml20"><span><i class="stretchImg stretchImgStyle"></i><i class="text">11</i></span><ul class="none"></ul></li>
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg5").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg6"></ul></li>')
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg6").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg7"></ul></li>')
            }
          } else if (data[0].parent.parent.parent.parent.parent.parent && !data[0].parent.parent.parent.parent.parent.parent.parent) {
            //                      如果最顶层组织有六个parent

            if (i == 0) {
              $(".devOrgList>div>div>ul").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg6"></ul></li>'); //<li class="orgml20"><span><i class="stretchImg stretchImgStyle"></i><i class="text">11</i></span><ul class="none"></ul></li>
            } else if (data[i].organization.parent.parent.parent.parent.parent.parent.parent && !data[i].organization.parent.parent.parent.parent.parent.parent.parent.parent) { //&& !data[i].organization.parent.parent
              $("#devOrg" + data[i].organization.parent.orgid + " .firstOrg6").append('<li class="orgml20" id="devOrg' + dataId + '"><span parentid="' + data[i].organization.id + '" path="' + data[i].organization.path + '"><i class="stretchImg stretchImgStyle"></i><i class="text">' + data[i].organization.orgName + ' ( <s class="color32ffd9"><s class="devNum">' + data[i].count + '</s>条</s> ) </i></span><ul class="none firstOrg7"></ul></li>')
            }
          }
        }
        $thisorgListspan = $('.devOrgList ._panel-box>ul>li>span');
        // devOrgImgTOggle();
      }
    });
    $(".devOrgList>div>div>ul>li>span>.text").addClass('active');
    $(".devOrgList>div>div>ul>li>span>.stretchImgStyle").addClass('shrinkImg');
    $(".devOrgList>div>div>ul>li>ul").show();
  }
  // 如果组织下没有子组织则去掉图标
  function devOrgImgTOggle() {
    $('.devOrgList li span').each(function () {
      var $this = $(this);
      if (!$this.siblings('ul').html()) {
        $this.find('.stretchImgStyle').removeClass('shrinkImg');
        $this.find('.stretchImgStyle').removeClass('stretchImg');
      }
    });
  }
  var path, parentid, $thisorgListspan;
  //设备管理 组织树切换
  $('.devOrgList').on('click', "span", function () {
    $('.devOrgList span .text').removeClass('active');
    $thisorgListspan = $(this);
    var $this = $(this);
    // orgId = $this.parent().attr('id');
    console.log(orgId)
    // orgId = orgId.substr(6);
    if ($this.siblings('ul').html()) {
      $this.siblings('ul').stop().slideToggle();
      // $this.find('.stretchImgStyle').toggleClass('shrinkImg');
    }
    $this.find('.text').toggleClass('active');
    $this.find('.stretchImgStyle').toggleClass('shrinkImg');
    path = $this.attr('path');
    parentid = $this.attr('parentid');
    orgId = parentid;

    var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
    var status = $('.searchDevStatusBox li.active').attr('myvalue');
    if (status == 'all') {
      status = '';
    } else {
      status = '&status=' + status;
    }
    $('.pageJump input').val('');
    var deviceTypeId = $('#configurationModal .deviceTypeSearchBtn').val();
    if (deviceTypeId == 'all') {
      deviceTypeId = '';
    } else {
      deviceTypeId = '&deviceTypeId=' + deviceTypeId;
    }

    configurationSumPage(configurationPage, devCode, status, deviceTypeId, orgId);
    configurationPageList(0, devCode, status, deviceTypeId, orgId);

  });

});